package com.tianpengtech.admin.taskscreenshot;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.jfinal.plugin.activerecord.Model;
import com.tianpengtech.common.exception.ValidateException;
import com.tianpengtech.admin.AbstractAdmin;
import com.tianpengtech.common.model.taskscreenshot.TaskScreenShot;
import com.tianpengtech.common.search.EqualCondition;
import com.tianpengtech.common.search.LikeCondition;
import com.tianpengtech.common.search.QueryConstructor;

public class TaskScreenShotAdminServiceImpl extends AbstractAdmin{

	@Override
	public void beforeAdd(Model<?> model) throws ValidateException {

	}

	@Override
	public void beforeQueryById(Model<?> model, int id) {

	}

	@Override
	public void beforeUpdate(Model<?> model) throws ValidateException {

	}

	@Override
	public void beforeDelete(Model<?> model) {

	}

	@Override
	public void builderSQLExpected(Model< ? > model,
			QueryConstructor queryConstruct, Map< String, Object > params) {
		setQuerySQLCommand(" select ts.* ");
		queryConstruct.setCommand(" from "+tableName()+" as ts,fair_task as t where ts.task_id=t.id ");
		String title = (String) model.get(TaskScreenShot.IMG);
		if(StringUtils.isNotEmpty(title)){
			queryConstruct.and(new LikeCondition(" and t.task_title", "%"+title+"%"));
		}
	}

	@Override
	public String tableName() {
		return TaskScreenShot.dao.tableName();
	}

}